How to change background of HTML page?

by elwin_wilderman , in category: HTML/CSS , 2 years ago

How to change background of HTML page?

Facebook Twitter LinkedIn Telegram Whatsapp

2 answers

by Ekaterina_90 , 2 years ago

@elwin_wilderman  To change the background color in HTML, use the style attribute. The style attribute specifies an inline style for an element.


1
2
3
4
5
6
7
<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
  </head>
  <body style="background-color: blue"></body>
</html>


by jerald.kuvalis , a year ago

@elwin_wilderman 

There are multiple ways to change the background of an HTML page, some of which are:

  1. Using CSS:


a) Inline CSS:


Using inline CSS, you can change the background of an HTML page by adding the style attribute to the body tag and setting the background-color property to the desired color value.


For example:

1
2
3
<body style="background-color: #abcdef;">
  <!-- HTML content here -->
</body>


b) Internal CSS:


Using Internal CSS, you can change the background of an HTML page by adding a style tag in the head section of the HTML document and setting the background-color property to the desired color value.


For example:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
<!DOCTYPE html>
<html>
<head>
  <style>
    body {
      background-color: #abcdef;
    }
  </style>
</head>
<body>
  <!-- HTML content here -->
</body>
</html>


c) External CSS:


Using External CSS, you can change the background of an HTML page by linking an external CSS file to your HTML document and setting the background-color property to the desired color value in that file.


For example:


HTML file:

1
2
3
4
5
6
7
8
9
<!DOCTYPE html>
<html>
<head>
  <link rel="stylesheet" type="text/css" href="style.css">
</head>
<body>
  <!-- HTML content here -->
</body>
</html>


CSS file (style.css):

1
2
3
body {
  background-color: #abcdef;
}


  1. Using HTML:


You can also change the background of an HTML page by adding a background attribute to the body tag and setting its value to the URL of the background image.


For example:

1
2
3
<body background="background.jpg">
  <!-- HTML content here -->
</body>